<script setup lang="ts">
import { useRouter } from 'vue-router'

const router = useRouter()
const props = defineProps<{
  title?: string
  rightTitle?: string
  patientShow?: () => void
}>()
const onClickLeft = () => {
  // 处理一些特殊需求，比如不想回退
  if (props.patientShow) return props.patientShow()
  if (history.state?.back) {
    router.back()
  } else {
    router.push('/')
  }
}

const emit = defineEmits<{
  (e: 'onClick'): void
}>()
// 不清楚右侧逻辑，点击后通知父处理对应逻辑即可
const onClickRight = () => {
  emit('onClick')
}
</script>
<template>
  <van-nav-bar
    left-arrow
    @click-left="onClickLeft"
    fixed
    :title="title"
    :right-text="rightTitle"
    @click-right="onClickRight"
  ></van-nav-bar>
</template>
<style scoped lang="scss"></style>
